package com.bsoft.gol.hcs.service.rpc.impl;

import com.bsoft.gol.hcs.service.rpc.IOdsHmRpcService;
import ctd.net.rpc.Client;
import ctd.spring.boot.annotation.SsdevService;
import hcn.protocol.ods.hm.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * iot健康监测接口实现
 */
@SsdevService(id = "odsHmRpcServiceImpl", name = "odsHmRpcService")
public class OdsHmRpcServiceImpl implements IOdsHmRpcService {

    private static Logger logger = LoggerFactory.getLogger(OdsHmRpcServiceImpl.class);


    @Override
    public GetTokenInfoReponse getIotToken() {
        try {
            return (GetTokenInfoReponse) Client.rpcInvoke("hcnInterface.modelFromHmService", "getIotToken");
        } catch (Throwable throwable) {
            logger.error("获取token失败：" + throwable.getMessage());
            return null;
        }
    }

    @Override
    public List<ModelListResponseVO> getModelList(String accessToken) {
        try {
            return (List<ModelListResponseVO>) Client.rpcInvoke("hcnInterface.modelFromHmService", "getModelList",accessToken);
        } catch (Throwable throwable) {
            logger.error("获取厂商设备列表失败：" + throwable.getMessage());
            return null;
        }
    }


    @Override
    public CheckModelReponse checkModel(CheckModelReq checkModelReq) {
        checkModelReq.setTemplateId("616f85be6b8c6e17d793d7c1");
        try {
            return (CheckModelReponse) Client.rpcInvoke("hcnInterface.modelFromHmService", "checkModel",checkModelReq);
        } catch (Throwable throwable) {
            logger.error("注册设备失败：" + throwable.getMessage());
            return null;
        }
    }

    @Override
    public List<GetHmRecordListReponse> getHmRecordList(GetHmRecordListReq getHmRecordListReq) {

        try {
            return (List<GetHmRecordListReponse>) Client.rpcInvoke("hcnInterface.modelFromHmService", "getHmRecordList",getHmRecordListReq);
        } catch (Throwable throwable) {
            logger.error("查询健康监测数据失败：" + throwable.getMessage());
            return null;
        }
    }
}
